Yacon.component.TTree = function(conText){
	
	Yacon.apply(this,conText);
	
	this.baseCreate();
	
};

Yacon.component.TTree.prototype = {
	
	baseCreate: function(){
		
		this.elementID = this.view.id;
		this.elementType = this.view.type;	
		
		this.dataSet = new Yacon.data.DataSet(this.page);
		this.dataSet.component = this;
		this.dataSet.elementID = this.elementID;
		this.dataSet.defaultMethod = this.view.excute;
		this.dataSet.refreshMethod = this.view.refresh;
		this.dataSet.setBody("treeParID",this.view.parId);
		this.dataSet.setBody("treeNowID",this.view.nowId);
		this.dataSet.setBody("treeNowName",this.view.nowName);
		this.dataSet.setBody("treeChildID",this.view.child);
		
		this.newCount = 1;
	},	
		
	getHtml: function(){
		
		var html = "";
		
		html += "<div style='overflow:auto; height:100%; width:100%;'>";
		
		html += "<div id='"+this.view.id+"' ";	
		
		html += " lily-id='"+this.view.id+"' lily-type='tree' ";
		
		html += " style='padding-bottom:15px;'>";
		
		html += "<ul id='"+this.view.id+"_Tree' class='ztree'></ul>";
		
		html += "</div>";
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 事件装载  */
	addEvents: function(){		
		this.loadTree();	
	},
	
	/* 树装载 */
	loadTree: function(){
		
		this.treeId = this.elementID+"_Tree";
		
		this.isEdit = this.view.isEdit;
		
		if(this.isEdit){
			
			this.setting = {
					
					data: {
						simpleData: {
							enable: true
						}
					},
					view: {
						addHoverDom: addHoverDom,
						removeHoverDom: removeHoverDom
					},
					async: {
						enable: true,
						url: zTreeUrl
					},
						
					edit:{
						enable:this.isEdit,
						removeTitle: "删除",
						renameTitle: "修改",
						showRemoveBtn: showRemoveBtn,
						showRenameBtn: showRenameBtn
					},
					
					callback: {
						beforeRemove: zTreeBeforeRemove,
						onRemove: zTreeAfterRemove,
						beforeRename: zTreeBeforeRename,
						onRename: zTreeAfterRename,
						beforeEditName: zTreeBeforeEditName,
						onClick: zTreeOnClick,
						onAsyncSuccess: zTreeAfterRefresh,
						beforeAsync: zTreeBeforeRefresh
					},
					
					lilyTree:this
					
				};
			
		}
		
		else{
			
			this.setting = {
					
				data: {
					simpleData: {
						enable: true
					}
				},
				async: {
					enable: true,
					url: zTreeUrl
				},
				
				callback: {
					onClick: zTreeOnClick,
					onAsyncSuccess: zTreeAfterRefresh
				},
				
				edit:{
					
				},
				
				lilyTree:this
				
			};
			
		}
		
		if(this.view.choice == "check"){
			this.setting.check = {
				enable: true
			}
		}
		
		else if(this.view.choice == "radio"){
			this.setting.check = {
				enable: true,
				chkStyle: "radio",
				radioType: this.view.radio
			}
		}
		
		this.rootID = this.view.rootId;
		this.rootName = this.view.rootName;
		
		//屏蔽拖拽
		this.setting.edit.drag = {
			isCopy: false,
			isMove: false	
		}
			
		this.zNodes =[
     		{ 
     		  name:this.rootName,
     		  isParent:true , 
     		  nodeID:this.rootID, 
     		  nodeName:this.rootName, 
              parentID:-1
     		}
     	];
		
		var self = this;
		
		$(document).ready(function(){
			$.fn.zTree.init($("#"+self.treeId), self.setting, self.zNodes);
					
			//选中并展开一个节点
			var treeObj = $.fn.zTree.getZTreeObj(self.treeId);
			var nodes = treeObj.getNodes();
			if (nodes.length>0) {
				
				if(self.view.expandMode == "first"){
					treeObj.reAsyncChildNodes(nodes[0], "refresh");
				}
				
				if(self.view.clickMode == "root"){
					
					/*treeObj.selectNode(nodes[0]);*/	
					
					if(!Yacon.isEmpty(nodes[0].click)){
						nodes[0].click();
					}
					
				}
				
			}
			
		});
		
	},
	
	/* 重置编辑节点 */
	resetEditNode: function(treeId,treeNode){		
		this.treeId = treeId;
		this.treeEditNode = treeNode;	
	},
	
	/* 重置编辑节点信息 */
	resetEditData:function(){
		this.dataSet.setBody("treeLevel" , this.treeEditNode.level);
		this.dataSet.setBody(this.view.parId , this.treeEditNode.nodeID);	
	},
	
	/* 重置点击节点 */
	resetClickNode:function(treeId,treeNode){	
		this.treeId = treeId;
		this.treeNode = treeNode;	
	},
	
	/* 重置点击节点信息 */
	resetClickData:function(){
		this.dataSet.setBody("treeLevel" , this.treeNode.level);
		this.dataSet.setBody(this.view.parId , this.treeNode.nodeID);	
	},
	
	/* 重置父节点 */
	resetParentNode:function(){
		this.treeParentNode = this.treeNode.getParentNode();
	},
	
	/* 刷新树 */
	refresh:function(treeId, treeNode){
		
		this.resetClickNode(treeId, treeNode);
		this.resetClickData();
				
		this.dataSet.setAction("methodType","treeRefresh");
		this.dataSet.setAction("methodName",this.dataSet.refreshMethod);
		
		return this.dataSet.getUrl();
	},
	
	/* 刷新父节点，必须在重置后使用 */
	refreshParent: function(treeId, treeNode){
		
		if(this.treeParentNode){
			var treeObj = $.fn.zTree.getZTreeObj(treeId);		
			treeObj.reAsyncChildNodes(this.treeParentNode, "refresh");
		}		
		
	},
	
	refreshActive: function(treeId, treeNode){
		
		var treeObj = $.fn.zTree.getZTreeObj(this.treeId);
		
		treeObj.reAsyncChildNodes(this.treeNode, "refresh");
		
	},
	
	/* 树展示 */
	show:function(treeId,treeNode,type){
		
		this.resetClickNode(treeId, treeNode);
		
		if(Yacon.isfireuserEvent(this.elementID+"_show")){
			return Yacon.fireUserEvent(this.elementID+"_show", [this,this.page,type]);
		}
		
		return true;
		
	},
	
	/* 增加前 */
	beforeAdd: function(treeId,treeNode){
		
		this.resetClickNode(treeId,treeNode);
		this.resetParentNode();
		
		if(Yacon.isfireuserEvent(this.elementID+"_beforeEdit")){
			return Yacon.fireUserEvent(this.elementID+"_beforeEdit", [this,this.page]);
		}
		
		return true;
		
	},
	
	addNode:function(treeId, treeNode, newName, isCancel){
		
		if(this.beforeAdd(treeId, treeNode)){
			
			this.dataSet.setBody("treeLevel",this.treeNode.level);
			this.dataSet.setBody(this.view.parId,this.treeNode.getParentNode().nodeID);	
			
			this.dataSet.setAction("methodName",this.dataSet.defaultMethod);
			this.dataSet.setAction("methodType","treeExcute");
			this.dataSet.setAction("type","1");
			this.dataSet.setDataSet(this.view.nowName,newName);
			
			this.dataSet.switchMessage();
			
			var result = this.dataSet.rsp.action.result;
			var msg = this.dataSet.rsp.action.message;
			var type = this.dataSet.rsp.action.type;
			
			if(result == "0000"){
							
				treeNode.nodeName = newName;				
				this.refreshParent(treeId,treeNode);				
				return true;
				
			}else{
				this.refreshParent(treeId,treeNode);
				return false;
			}
			
		}
		
		this.afterAdd(treeId, treeNode);
		
	},
	
	/* 增加后处理 */
	afterAdd: function(treeId,treeNode){
		
		if(Yacon.isfireuserEvent(this.elementID+"_afterAdd")){
			return Yacon.fireUserEvent(this.elementID+"_afterAdd", [this,this.page]);
		}
		
		return true;
		
	},
	
	/* 修改前处理 */
	beforeEdit: function(treeId,treeNode){
		
		this.resetClickNode(treeId, treeNode);
		this.resetClickData();
		
		this.resetEditNode(treeId, treeNode);
		this.resetEditNode();
		
		//重置父节点
		this.resetParentNode();
		
		if(Yacon.isfireuserEvent(this.elementID+"_beforeEdit")){
			return Yacon.fireUserEvent(this.elementID+"_beforeEdit", [this,this.page]);
		}
		
		return true;
		
	},
	
	/* 修改 */
	editNode:function(treeId, treeNode, newName, isCancel){
		
		if(this.beforeEdit(treeId, treeNode)){
			
			this.dataSet.setAction("methodName",this.dataSet.defaultMethod);
			this.dataSet.setAction("methodType","treeExcute");
			this.dataSet.setAction("type","2");
			
			/* 节点非空 */
			if(!Yacon.isEmpty(treeNode.dataSet)){
				
				for(var prp in treeNode.dataSet){
					this.dataSet.setDataSet(prp,treeNode.dataSet[prp].fieldvalue,treeNode.dataSet[prp].fieldoldvalue);
				}
				
			}
			
			this.dataSet.getFieldValue(this.view.nowName).setFieldValue("fieldvalue",newName);
			
			this.dataSet.switchMessage();
			
			var result = this.dataSet.rsp.action.result;
			var msg = this.dataSet.rsp.action.message;
			var type = this.dataSet.rsp.action.type;
			
			if(result == "0000"){			
				
				//刷新
				this.refreshParent(treeId, treeNode);
				
				return true;
				
			}else{				
				return false;
			}
			
		}
		
		this.afterEdit(treeId, treeNode);
		
	},
	
	/* 修改后处理 */
	afterEdit: function(treeId,treeNode){
		
		if(Yacon.isfireuserEvent(this.elementID+"_afterEdit")){
			return Yacon.fireUserEvent(this.elementID+"_afterEdit", [this,this.page]);
		}
		
		return true;
		
	},
	
	/* 删除前处理 */
	beforeDelete: function(treeId, treeNode){
		
		this.resetClickNode(treeId, treeNode);
		this.resetClickData();
		
		this.resetEditNode(treeId, treeNode);
		this.resetEditNode();
		
		//重置父节点
		this.resetParentNode();
		
		if(Yacon.isfireuserEvent(this.elementID+"_beforeDelete")){
			return Yacon.fireUserEvent(this.elementID+"_beforeDelete", [this,this.page]);
		}
		
		return true;
	},
	
	/* 删除处理 */
	deleteNode:function(treeId, treeNode){
		
		if(this.beforeDelete(treeId, treeNode)){
			
			if(!window.confirm("确定要删除数据吗？")){
				return false;
			}
			
			this.dataSet.setAction("methodName",this.dataSet.defaultMethod);
			this.dataSet.setAction("methodType","treeExcute");
			this.dataSet.setAction("type","3");
			
			/* 节点非空 */
			if(!Yacon.isEmpty(treeNode.dataSet)){			
				for(var prp in treeNode.dataSet){
					this.dataSet.setDataSet(prp,treeNode.dataSet[prp].fieldvalue,treeNode.dataSet[prp].fieldoldvalue);
				}			
			}
			
			this.dataSet.switchMessage();
			
			var result = this.dataSet.rsp.action.result;
			var msg = this.dataSet.rsp.action.message;
			var type = this.dataSet.rsp.action.type;
			
			if(result == "0000"){		
				return true;
			}else{					
				return false;
			}
			
		}
		
		return false;
		
	},
	
	/* 删除后处理 */
	afterDelete: function(treeId, treeNode){
		
		this.refreshParent(treeId, treeNode);
		
		if(Yacon.isfireuserEvent(this.elementID+"_afterDelete")){
			return Yacon.fireUserEvent(this.elementID+"_afterDelete", [this,this.page]);
		}
		
		return true;
	},
	
	/* 修改名称 - 增加、修改都预先走该部分 */
	editName: function(treeId, treeNode){
		
		this.resetEditNode(treeId, treeNode);
		this.resetClickNode(treeId,treeNode);
		this.resetParentNode();
		
		var element = "";
		
		if(Yacon.isfireuserEvent(this.elementID+"_page")){
			element = Yacon.fireUserEvent(this.elementID+"_page", [this,this.page]);
		}
		
		if(Yacon.isEmpty(element)){
			return true;
		}else{
						
			this.dataSet.setAction("methodName",this.dataSet.defaultMethod);
			this.dataSet.setAction("methodType","treeExcute");
			
			if(treeNode.nodeTyp == "add"){			
				
				this.dataSet.setBody("treeLevel" , this.treeNode.level);
				this.dataSet.setBody(this.view.parId , this.treeNode.getParentNode().nodeID);	
				
				this.dataSet.setAction("type","1");
				
			}else{
				
				this.resetClickData();
				
				this.dataSet.setAction("type","2");		
				
			}
			
			if(!Yacon.isEmpty(treeNode.dataSet)){
				
				for(var prp in treeNode.dataSet){
					this.dataSet.setDataSet(prp,treeNode.dataSet[prp].fieldvalue,treeNode.dataSet[prp].fieldoldvalue);
				}
				
			}
			
			var autoClose = element.autoClose ;
			if(autoClose == undefined){
				autoClose = true;
			}
			
			if(treeNode.nodeTyp == "add"){
				
				var url = Yacon.addUrlParam("state", "insert", element.url);
				
				Yacon.showModal({
					width: element.width ,
					height: element.height ,
					url : url ,
					dataSet : this.dataSet,
					autoClose : autoClose,
					close:{
						method:"zTreeRefreshParent",
						param:[this,this.page]
					}
				});
				
			}else{
				
				var url = Yacon.addUrlParam("state", "edit", element.url);
				
				Yacon.showModal({
					width: element.width ,
					height: element.height ,
					url : url ,
					dataSet : this.dataSet,
					autoClose : autoClose,
					close:{
						method:"zTreeRefreshParent",
						param:[this,this.page]
					}
				});
				
			}
			
			return false;
			
		}
		
	},
	
	/* 添加按钮控制 */
	addDom:function(treeId, treeNode){
		
		this.resetClickNode(treeId, treeNode);
		
		var sObj = $("#" + treeNode.tId + "_span");
		
		var isShow = true;
		
		isShow = this.show(treeId, treeNode,"add");
		
		var self = this;
		
		if(isShow){
			
			if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
			var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
				+ "' title='增加' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var btn = $("#addBtn_"+treeNode.tId);
			if (btn) btn.bind("click", function(){
				
				var zTree = $.fn.zTree.getZTreeObj(treeId);
				
				//树是否展开判断
				if(treeNode.isParent && !treeNode.open ){
					
					zTree.reAsyncChildNodes(treeNode, "refresh" , false , function(){
						
						var active = zTree.addNodes(treeNode, {pId:treeNode.id,nodeTyp:"add", name:"new node" + (self.newCount++),dataSet:[]});
						
						if(zTreeBeforeEditName(treeId,active[0])){
							zTree.editName(active[0]);
						}	
						
					});
					
				}else{
					
					var active = zTree.addNodes(treeNode, {pId:treeNode.id,nodeTyp:"add", name:"new node" + (self.newCount++),dataSet:[]});
					
					if(zTreeBeforeEditName(treeId,active[0])){
						zTree.editName(active[0]);
					}
					
				}
					
				return false;
			});
			
		}
		
	},
	
	/* 初始化数据 - 与Grid 重复 */
	instData: function(){
		
		var typ = this.dataSet.getAction("type");		

		if(typ == "1"){
			this.insertDataSet();
		}
		
		else if(typ == "2"){
			this.editDataSet();
		}
		
		else if(typ == "3"){
			
		}
		
		return true;

	},
	
	/* 初始化数据 - 与Grid 重复 */
	insertDataSet: function(){
			
		var alls;
		
		this.control = "#"+this.elementID+"_window ";
		
		if(this.control){			
			alls = $(this.control+" .lily-field");		
		}else{
			alls = $(".lily-field");
		}
		
		if(alls){
			
			var size = alls.length;	
			
			this.dataSet.dataset = new Yacon.container.Table();
			
			this.dataSet.getFirstRecord();	
			
			for(var i=0;i<size;i++){
			
				var active = alls.eq(i);
				var fieldName = active.attr("field-name");
				var fieldValue = active.val();
				
				if(Yacon.isNull(fieldValue)){
					fieldValue = "";
				}
				
				//校验字段
				if(!this.checkField(active)){
					Yacon.throwException(); 
				};
				
				//复选框
				var fieldTyp = active.attr("field-type");
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
					var allChecks = active.find("input[type='checkbox']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//单选框
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){
					var allChecks = active.find("input[type='radio']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//Label信息
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){
					fieldValue = active.html();
				}
				
				var fieldOldValue = fieldValue;
				
				this.dataSet.setDataSet(fieldName,fieldValue,fieldOldValue);
				
			}
			
		}
		
	},
	
	/* 初始化数据 - 与Grid 重复 */
	editDataSet: function(){
		
		var alls;
		
		if(this.control){			
			alls = $(this.control+" .lily-field");		
		}else{
			alls = $(".lily-field");
		}
		
		if(alls){
			
			var size = alls.length;	
			this.dataSet.getFirstRecord();	
			
			for(var i=0;i<size;i++){
			
				var active = alls.eq(i);
				var fieldName = active.attr("field-name");
				var fieldValue = active.val();
				
				if(Yacon.isNull(fieldValue)){
					fieldValue = "";
				}
				
				//校验字段
				if(!this.checkField(active)){
					Yacon.throwException(); 
				};
				
				//复选框
				var fieldTyp = active.attr("field-type");
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
					
					fieldValue = "";
					
					var allChecks = active.find("input[type='checkbox']:checked");
					
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
				}
				
				//单选框
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){
					fieldValue = "";
					var allChecks = active.find("input[type='radio']:checked");
					for(var j=0;j<allChecks.length;j++){
						fieldValue += ","+allChecks.eq(j).attr("field-key") ;
					}
					
					if(fieldValue.startsWith(",")){
						fieldValue = fieldValue.substring(1);
					}
					
				}
				
				//Label信息
				if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){
					fieldValue = active.html();
				}
				
				var activeRecord = this.dataSet.getFieldValue(fieldName);
				
				if(Yacon.isEmpty(activeRecord)){
					this.dataSet.setDataSet(fieldName,"");
				}
				
				this.dataSet.getFieldValue(fieldName).setFieldValue("fieldvalue",fieldValue);
						
			}
			
		}
	},
	
	/* 数据展现 - 与Grid 重复 */
	showData: function(){
		
		var record = this.dataSet.getFirstRecord();
		var fieldSize = record.getFieldCount();
		
		for(var i=0;i<fieldSize;i++){
			
			var field = record.getField(i);			
			var fieldName = field.getFieldName();			
			var fieldValue = field.getFieldValue().getFieldValue("fieldoldvalue");	
			
			this.control = "#"+this.elementID +"_window";
			
			var formField = $(this.control+" .lily-field[field-name='"+fieldName+"']");
			var fieldTyp = formField.attr("field-type");
			
			/* 复选框 */
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "check"){
				var item = fieldValue.split(",");
				for(var j=0;j<item.length;j++){					
					var itemVal = item[j];				
					formField.find("input[field-key='"+itemVal+"']")
					         .prop("checked","true");				
				}			
			}
			
			/* 单选框 */
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "radio"){			
				formField.find("input[field-key='"+fieldValue+"']")
				         .prop("checked","true");							
			}
			
			//Label信息
			if(!Yacon.isEmpty(fieldTyp) && fieldTyp == "label"){
				formField.html(fieldValue);
			}
			
			else{
				$(this.control+" .lily-field[field-name='"+fieldName+"']").val(fieldValue);
				$(this.control+" .lily-fix-field[field-fix-name='"+fieldName+"']").val(fieldValue);
			}
			
		}
	},
	
	/* 点击处理 */
	nodeClick: function(event, treeId, treeNode){
		
		this.resetClickNode(treeId, treeNode);
		
		Yacon.callBack(this.elementID+"_onclick", [this,this.page]);
		
		var frameID = this.view.frameID;
		
		if(!Yacon.isEmpty(frameID)){	
			
			var frame = this.page.find(frameID);
			frame.clear();
			frame.show();
		}
		
	},
	
	layoutBefore: function(){
		
	},
	
	
	refreshElement: function(){
		
	},
	
	getZtree: function(){
		this.zTree = $.fn.zTree.getZTreeObj(this.treeId);
		return this.zTree;
	},
	
	/* 获取复选节点 */
	getCheckNodes: function(param){
		
		if(Yacon.isEmpty(param)){
			return this.getCheckAllNodes();
		}
		
		else if(param == "leaf"){
			return this.getCheckLeafNodes();
		}
		
		else if(param == "parent"){
			return this.getCheckParentNodes();
		}
		
		else if(Yacon.isNumber(param)){
			return this.getCheckLevelNode(param);
		}
		
		else{
			return this.getCheckAllNodes();
		}
			
	},
	
	getCheckNodesIds: function(param){
		
		var node = this.getCheckNodes(param);
		var nodeIDs = "";
		
		for(var i=0;i<node.length;i++){
			
			nodeIDs += "," + node[i].nodeID;
			
		}
		
		if(!Yacon.isEmpty(nodeIDs)){
			nodeIDs = nodeIDs.substring(1);
		}
		
		return nodeIDs;
		
	},
	
	getCheckNodesCaptions: function(param){
		
		var node = this.getCheckNodes(param);
		var nodeNames = "";
		
		for(var i=0;i<node.length;i++){
			
			nodeNames += "," + node[i].name;
			
		}
		
		if(!Yacon.isEmpty(nodeNames)){
			nodeNames = nodeNames.substring(1);
		}
		
		return nodeNames;
		
	},
	
	getCheckNodesIdAndCaptions: function(param){
		
		var node = this.getCheckNodes(param);
		
		var nodeNames = "";
		
		for(var i=0;i<node.length;i++){
			
			nodeNames += "," + node[i].nodeID +"#"+ node[i].name;
			
		}
		
		if(!Yacon.isEmpty(nodeNames)){
			nodeNames = nodeNames.substring(1);
		}
		
		return nodeNames;
		
	},
	
	getCheckAllNodes: function(){		
		this.getZtree();
		return this.zTree.getCheckedNodes(true);
	},
	
	getUnCheckAllNodes: function(){
		this.getZtree();
		return this.zTree.getCheckedNodes(false);
	},
	
	getCheckLeafNodes: function(){
		
		var checkNodes = this.getCheckAllNodes();
		var retNodes = new Array();
		
		for(var i=0;i<checkNodes.length;i++){
			var activeNode = checkNodes[i];
			
			if(!activeNode.isParent){
				retNodes.add(activeNode);
			}
		}
		
		return retNodes;
		
	},
	
	getCheckParentNodes: function(){
		
		var checkNodes = this.getCheckAllNodes();
		var retNodes = new Array();
		
		for(var i=0;i<checkNodes.length;i++){
			var activeNode = checkNodes[i];
			if(activeNode.isParent){
				retNodes.add(activeNode);
			}
		}
		
		return retNodes;
		
	},
	
	getCheckLevelNode:function(level){
		
		var checkNodes = this.getCheckAllNodes();
		var retNodes = new Array();
		
		for(var i=0;i<checkNodes.length;i++){
			var activeNode = checkNodes[i];
			if(activeNode.level == level){
				retNodes.add(activeNode);
			}
		}
		
		return retNodes;
		
	},
	
	getRadioAllNodes: function(){		
		this.getZtree();
		return this.zTree.getCheckedNodes(true);
	},
	
	getUnRadioAllNodes: function(){
		this.getZtree();
		return this.zTree.getCheckedNodes(false);
	},
	
	/* 获取子节点 */
	getChildNodes: function(){
		return this.treeNode.children;
	},
	
	/* 刷新后 */
	afterRefresh: function(treeId, treeNode){		
		Yacon.callBack(this.elementID+"_afterRefresh", [this,this.page]);	
	},
	
	/* 刷新前 */
	beforeRefresh: function(treeId,treeNode){
		Yacon.callBack(this.elementID+"_beforeRefresh", [this,this.page]);
	},
	
	/* 点击 节点 */
	clickNode: function(treeNode){
		$("#"+treeNode.tId+"_a").trigger("click");
	},
	
	/* 点击第一个子节点  */
	clickChildNode: function(treeNode){
		var childs = treeNode.children;
		if(childs.length>0){		
			$("#"+childs[0].tId+"_a").trigger("click");			
		}
	},
	
	checkField:function(active){
		
		var fieldLabel = active.attr("field-label");
		var fieldValue = active.val();
		var fieldType = active.attr("field-type");
		var fieldMaxLength = Yacon.getInt(active.attr("field-max-length"));
		
		if(fieldType == "input" || fieldType == "textarea"){
			
			if(fieldMaxLength == 0){
				return true;
			}
			
			if(fieldValue.length > fieldMaxLength){
				alert(fieldLabel+"信息过长！");
				return false;
			}
			
		}
		
		return true;
	}
};

/* 刷新树 */
function zTreeUrl(treeId, treeNode){	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;	
	return tree.refresh(treeId, treeNode);	
};

/* 删除前 */
function zTreeBeforeRemove(treeId, treeNode){	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;
	return tree.deleteNode(treeId, treeNode);	
};

/* 删除后 */
function zTreeAfterRemove(event, treeId, treeNode){
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;	
	tree.afterDelete(treeId, treeNode);
};

/* 修改前 */
function  zTreeBeforeRename(treeId, treeNode, newName, isCancel){
	
	/* 添加 */
	if(treeNode.nodeTyp == "add"){
		zTreeAdd(treeId, treeNode, newName, isCancel);
	}
	
	/* 修改 */
	else{
		zTreeEdit(treeId, treeNode, newName, isCancel);
	}
};

/* 树增加 */
function zTreeAdd(treeId, treeNode, newName, isCancel){	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;	
	tree.addNode(treeId, treeNode, newName, isCancel);	
};

/* 树修改 */
function zTreeEdit(treeId, treeNode, newName, isCancel){	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;	
	tree.editNode(treeId, treeNode, newName, isCancel);	
};

/* 修改后 */
function zTreeAfterRename(event, treeId, treeNode, isCancel) {
	
};

/* 修改前处理 */
function zTreeBeforeEditName(treeId, treeNode) {	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);	
	var tree = treeObj.setting.lilyTree;
	return tree.editName(treeId, treeNode);
};

/* 删除展示控制 */
function showRemoveBtn(treeId, treeNode) {
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;	
	return tree.show(treeId, treeNode,"delete");
};

/* 修改展示控制 */
function showRenameBtn(treeId, treeNode) {	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;	
	return tree.show(treeId, treeNode,"edit");
};

/* 自定义添加 */
function addHoverDom(treeId, treeNode) {	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;
	return tree.addDom(treeId, treeNode);
};

/* 自定义添加移除 */
function removeHoverDom(treeId, treeNode) {
	$("#addBtn_"+treeNode.tId).unbind().remove();
};

/* 刷新父节点 */
function zTreeRefreshParent(tree,page){	
	tree.refreshParent(tree.treeId,tree.treeNode);
};

/* 刷新当前节点 */
function zTreeRefreshActive(tree,page){	
	tree.refreshActive(tree.treeId,tree.treeNode);
};

/* 树点击回调 */
function zTreeOnClick(event, treeId, treeNode){
	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;	
	tree.nodeClick(event, treeId, treeNode);
	
};

/* 刷新后回调 */
function zTreeAfterRefresh(event, treeId, treeNode, msg){
	
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;		
	tree.afterRefresh(treeId,treeNode);	
	
};

/* 刷新前回调 */
function zTreeBeforeRefresh(treeId, treeNode){
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var tree = treeObj.setting.lilyTree;
	tree.beforeRefresh(treeId,treeNode);
};

function zTreeChange(element){
	if(!Yacon.isEmpty(element.url) && !Yacon.isEmpty(element.frameID)){		
		$("#"+element.frameID).attr("page-path",element.url);			
	}
};